package common;

import java.io.Serializable;

/**
 * Created by lx on 2017/7/2.
 * 构造返回结果对象
 */
public class Result<T> implements Serializable{

    private static final long serialVersionUID = 1L;

    private T data;

    private Integer code;

    private String successMessage;

    private String errorMessage;

    private boolean isSuccess;

    private Long total;

    private Object title;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getSuccessMessage() {
        return successMessage;
    }

    public void setSuccessMessage(String successMessage) {
        this.successMessage = successMessage;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public boolean getIsSuccess() {
        return isSuccess;
    }

    public void setSuccess(boolean success) {
        isSuccess = success;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public void sucess(){

    }

    public Object getTitle() {
        return title;
    }

    public void setTitle(Object title) {
        this.title = title;
    }

    public static <T> Result<T> sucess(Integer code, T data , String successMessage, Long total,Object title){
        Result<T> result = new Result<T>();
        result.data = data;
        result.code = code;
        result.successMessage = successMessage;
        result.total = total;
        result.isSuccess = true;
        result.title = title;
        return result;
    }
    public static <T> Result<T> sucess(T data , String successMessage, Long total){
        return sucess(CommonCode.SUCES.getCode(),data,successMessage,total,null);
    }
    public static <T> Result<T> sucess(T data , Long total){
        return sucess(CommonCode.SUCES.getCode(),data,CommonCode.SUCES.getMes(),total,null);
    }
    public static <T> Result<T> sucess(T data ){
        return sucess(CommonCode.SUCES.getCode(),data,CommonCode.SUCES.getMes(),null,null);
    }

    public static <T> Result<T> error(Integer code,String errorMessage){
        Result<T> result = new Result<T>();
        result.isSuccess = false;
        result.code = code;
        result.errorMessage = errorMessage;
        return result;
    }
    public static <T> Result<T> error(String errorMessage){
        return error(CommonCode.ERROR.getCode(),errorMessage);
    }
    public static <T> Result<T> error(){
        return error(CommonCode.ERROR.getCode(),CommonCode.ERROR.getMes());
    }
}
